<?php

namespace App\Jobs;

use App\Models\CarModels\CarInfo;
use App\Models\CarModels\CarRent;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class SendStartRentCar implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $car_id;
    protected $status;
    protected $rent_id;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($rent_id,$car_id,$status)
    {
        //
        $this->car_id = $car_id;
        $this->rent_id = $rent_id;
        $this->status = $status;

    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $rent = CarRent::find($this->rent_id);
        if($rent->apply_status == 2){
            $car = CarInfo::find($this->car_id);
            Log::info('id'.$this->car_id);
            Log::info(json_encode($car));
            $car->status = $this->status;
            $car->save();
        }

    }
}
